<template>
  <a-card style="margin-top:-2px" :bordered="false">
    <div class="">
      <a-form >
        <!--查询条件 start-->
        <a-row class="form-row" >
          <a-col :span="6" :offset="1">
            <a-form-item
              label="账号"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol">
              <a-input style="width:210px" v-model="queryParam.accout"/>
            </a-form-item>
          </a-col>
          <a-col :span="6" :offset="1">
            <a-form-item
              label="姓名"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol">
              <a-input style="width:210px" v-model="queryParam.name"/>
            </a-form-item>
          </a-col>
          <a-col :span="6" :offset="1">
            <a-form-item
              label="邮箱"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol">
              <a-input style="width:210px" v-model="queryParam.email"/>
            </a-form-item>
          </a-col>
          <a-col :span="6" :offset="1">
            <a-form-item
              label="部门"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol">
              <a-tree-select
                      :dropdownStyle="{ maxHeight: '200px', overflow: 'auto' }"
                      :treeData="treeOfOrg"
                      treeDefaultExpandAll
                      allowClear
                      @change="orgChange"
                      style="width:100%"
                      :value="orgid"
              ></a-tree-select>
              <!--<a-select
                placeholder="请选择"
                style="width:210px"
                v-model="queryParam.deptCode"
              >
                <a-select-option v-for="item in deptInfo" :key="item.codeValue" :value="item.codeValue" >{{ item.codeName }}</a-select-option>
              </a-select>-->
            </a-form-item>
          </a-col>
          <a-col :span="6" :offset="1">
            <a-form-item
              label="员工类型"
              :labelCol="labelCol"
              :wrapperCol="wrapperCol">
              <a-input style="width:210px" v-model="queryParam.yglx"/>
            </a-form-item>
          </a-col>
        </a-row>
        <!--查询条件 end-->
        <!--操作按钮 start -->
        <a-row :gutter="24" algin="center" style="margin-top:10px" >
          <a-col :md="12">
            <span style="float:right" class="table-page-search-submitButtons">
              <a-button type="primary" @click="search">查询</a-button>
              <a-button style="margin-left: 8px" @click="() => queryParam = {}">重置</a-button>
            </span>
          </a-col>

          <a-col :md="11" >
            <span class="table-page-search-submitButtons">
              <a-button type="primary" style="margin-left: 8px;float:right" :loading="loading" @click="exportExcel()">导出</a-button>
            </span>
            <!-- <span class="table-page-search-submitButtons">
              <a-button type="primary" style="margin-left: 8px;float:right" @click="modelMethod('add',{})" v-action:add>新增</a-button>
            </span> -->
          </a-col>

        </a-row>
        <!--操作按钮 end -->
      </a-form>
    </div>
    <s-table
      class="text-overflow"
      ref="stable"
      size="default"
      :columns="columns"
      :data="loadData"
      style="margin-top:10px"
      :scroll="{ x: 6000 }"
    >
      <span slot="action" slot-scope="text, record">
        <a @click="modelMethod('detile',record)">详情</a>
        <!--
        <a-divider type="vertical" />
        <a @click="modelMethod('del',record)" v-action:delete>删除</a>
        <a-divider type="vertical" />
        <a @click="modelMethod('edit',record)" v-action:update>编辑</a>
        -->
      </span>
    </s-table>
    <!-- 弹出框 -->
    <a-modal
      :title="operate=='detile'?'详情':operate=='edit'?'编辑':'新增'"
      style="top: 0px;"
      :width="900"
      v-model="modelVisible"
      @ok="handleOk"
      :destroyOnClose="true"
      :confirmLoading="confirmLoading"
    >
      <a-form :form="form">
        <a-row class="form-row" >
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="钉钉用户ID" >
              <a-input v-model="selectInfo.userId" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="账号" >
              <a-input v-model="selectInfo.accout" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="姓名" >
              <a-input v-model="selectInfo.name" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="邮箱" >
              <a-input v-model="selectInfo.email" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="部门" >
              <a-input v-model="selectInfo.orgName" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="职位" >
              <a-input v-model="selectInfo.position" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="手机号" >
              <a-input v-model="selectInfo.phone" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="办公地点" >
              <a-input v-model="selectInfo.bgdd" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="入职时间" >
              <a-input v-model="selectInfo.rzsj" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="司龄" >
              <a-input v-model="selectInfo.sl" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="社保缴纳地" >
              <a-input v-model="selectInfo.sbjnd" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="员工类型" >
              <a-input v-model="selectInfo.yglx" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="试用期" >
              <a-input v-model="selectInfo.syq" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="转正日期" >
              <a-input v-model="selectInfo.zzrq" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="岗位职级" >
              <a-input v-model="selectInfo.gwzj" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="身份证姓名" >
              <a-input v-model="selectInfo.sfzxm" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="证件号码" >
              <a-input v-model="selectInfo.zjhm" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="出生日期" >
              <a-input v-model="selectInfo.csrq" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="年龄" >
              <a-input v-model="selectInfo.age" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="性别" >
              <a-input v-model="selectInfo.sex" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="名族" >
              <a-input v-model="selectInfo.nation" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="身份证地址" >
              <a-input v-model="selectInfo.sfzdz" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="证件有效期" >
              <a-input v-model="selectInfo.zjyxq" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="婚姻状况" >
              <a-input v-model="selectInfo.hyzk" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="首次参加工作时间" >
              <a-input v-model="selectInfo.sccjgzsj" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="工龄" >
              <a-input v-model="selectInfo.gl" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="户籍类型" >
              <a-input v-model="selectInfo.hjlx" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="住址" >
              <a-input v-model="selectInfo.zz" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="政治面貌" >
              <a-input v-model="selectInfo.zzmm" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="学历" >
              <a-input v-model="selectInfo.xl" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="毕业院校" >
              <a-input v-model="selectInfo.byyx" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="毕业时间" >
              <a-input v-model="selectInfo.bysj" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="所学专业" >
              <a-input v-model="selectInfo.sxzy" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="银行卡号" >
              <a-input v-model="selectInfo.yhkh" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="开户行" >
              <a-input v-model="selectInfo.khh" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="合同公司" >
              <a-input v-model="selectInfo.htgs" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="合同类型" >
              <a-input v-model="selectInfo.htlx" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="首次合同起始日" >
              <a-input v-model="selectInfo.schtqsr" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="首次合同到期日" >
              <a-input v-model="selectInfo.schtdqr" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="现合同起始日" >
              <a-input v-model="selectInfo.xhtqsr" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="现合同到期日" >
              <a-input v-model="selectInfo.xhtdqr" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="合同期限" >
              <a-input v-model="selectInfo.htqx" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="续签次数" >
              <a-input v-model="selectInfo.xqcs" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="紧急联系人姓名" >
              <a-input v-model="selectInfo.jjlxrxm" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="联系人关系" >
              <a-input v-model="selectInfo.lsxgx" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="联系人电话" >
              <a-input v-model="selectInfo.lsxdh" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="家人姓名" >
              <a-input v-model="selectInfo.jrxm" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="家人关系" >
              <a-input v-model="selectInfo.jrgx" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="数据来源" >
              <a-input v-model="selectInfo.sjly" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="员工状态" >
              <a-input v-model="selectInfo.ygzt" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="离职日期" >
              <a-input v-model="selectInfo.lzsj" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="离职原因" >
              <a-input v-model="selectInfo.lzyy" :disabled="operate=='detile'?'disabled':false"/>
            </a-form-item>
          </a-col>
          <a-col :span="10" :offset="1">
          </a-col></a-row></a-form>
    </a-modal>
  </a-card>
</template>
<script>
import { STable } from '@/components'
import { query, method, download , getOrgTree} from '@/api/admin'

export default {
  components: {
    STable
  },
  data () {
    return {
      visible: false,
      form: this.$form.createForm(this),
      // 查询参数
      queryParam: {},

      inAdd: false,
      inEdit: false,
      inDetail: false,

      // 加载数据方法 必须为 Promise 对象
      loadData: parameter => {
        return query('/admin/staff' + '/page', 'GET', Object.assign(parameter, this.queryParam))
          .then(res => {
            return res.result
          })
      },
      // 表头
      columns: [
        {
          title: '钉钉用户ID',
          dataIndex: 'userId',
          ellipsis: true
        },
        {
          title: '账号',
          dataIndex: 'accout',
          ellipsis: true
        },
        {
          title: '姓名',
          dataIndex: 'name'
        },
        {
          title: '邮箱',
          dataIndex: 'email',
          ellipsis: true
        },
        {
          title: '部门',
          dataIndex: 'orgName',
          ellipsis: true
        },
        {
          title: '职位',
          dataIndex: 'position'
        },
        {
          title: '手机号',
          dataIndex: 'phone'
        },
        {
          title: '办公地点',
          dataIndex: 'bgdd'
        },
        {
          title: '入职时间',
          dataIndex: 'rzsj'
        },
        {
          title: '司龄',
          dataIndex: 'sl'
        },
        {
          title: '社保缴纳地',
          dataIndex: 'sbjnd'
        },
        {
          title: '员工类型',
          dataIndex: 'yglx'
        },
        {
          title: '试用期',
          dataIndex: 'syq'
        },
        {
          title: '转正日期',
          dataIndex: 'zzrq'
        },
        {
          title: '岗位职级',
          dataIndex: 'gwzj'
        },
        {
          title: '身份证姓名',
          dataIndex: 'sfzxm'
        },
        {
          title: '证件号码',
          dataIndex: 'zjhm',
          ellipsis: true
        },
        {
          title: '出生日期',
          dataIndex: 'csrq'
        },
        {
          title: '年龄',
          dataIndex: 'age'
        },
        {
          title: '性别',
          dataIndex: 'sex'
        },
        {
          title: '名族',
          dataIndex: 'nation'
        },
        {
          title: '身份证地址',
          dataIndex: 'sfzdz',
          ellipsis: true
        },
        {
          title: '证件有效期',
          dataIndex: 'zjyxq'
        },
        {
          title: '婚姻状况',
          dataIndex: 'hyzk'
        },
        {
          title: '首次参加工作时间',
          dataIndex: 'sccjgzsj'
        },
        {
          title: '工龄',
          dataIndex: 'gl'
        },
        {
          title: '户籍类型',
          dataIndex: 'hjlx'
        },
        {
          title: '住址',
          dataIndex: 'zz',
          ellipsis: true
        },
        {
          title: '政治面貌',
          dataIndex: 'zzmm'
        },
        {
          title: '学历',
          dataIndex: 'xl'
        },
        {
          title: '毕业院校',
          dataIndex: 'byyx',
          ellipsis: true
        },
        {
          title: '毕业时间',
          dataIndex: 'bysj'
        },
        {
          title: '所学专业',
          dataIndex: 'sxzy',
          ellipsis: true
        },
        {
          title: '银行卡号',
          dataIndex: 'yhkh',
          ellipsis: true
        },
        {
          title: '开户行',
          dataIndex: 'khh',
          ellipsis: true
        },
        {
          title: '合同公司',
          dataIndex: 'htgs',
          ellipsis: true
        },
        {
          title: '合同类型',
          dataIndex: 'htlx',
          ellipsis: true
        },
        {
          title: '首次合同起始日',
          dataIndex: 'schtqsr'
        },
        {
          title: '首次合同到期日',
          dataIndex: 'schtdqr'
        },
        {
          title: '现合同起始日',
          dataIndex: 'xhtqsr'
        },
        {
          title: '现合同到期日',
          dataIndex: 'xhtdqr'
        },
        {
          title: '合同期限',
          dataIndex: 'htqx'
        },
        {
          title: '续签次数',
          dataIndex: 'xqcs'
        },
        {
          title: '紧急联系人姓名',
          dataIndex: 'jjlxrxm'
        },
        {
          title: '联系人关系',
          dataIndex: 'lsxgx'
        },
        {
          title: '联系人电话',
          dataIndex: 'lsxdh'
        },
        {
          title: '家人姓名',
          dataIndex: 'jrxm'
        },
        {
          title: '家人关系',
          dataIndex: 'jrgx'
        },
        {
          title: '数据来源',
          dataIndex: 'sjly'
        },
        {
          title: '员工状态',
          dataIndex: 'ygzt'
        },
        {
          title: '离职日期',
          dataIndex: 'lzsj'
        },
        {
          title: '离职原因',
          dataIndex: 'lzyy'
        },
        {
          title: '操作',
          width: '100px',
          fixed: 'right',
          dataIndex: 'action',
          scopedSlots: { customRender: 'action' }
        }
      ],
      labelCol: {
        xs: { span: 24 },
        sm: { span: 8 }
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 16 }
      },
      modelVisible: false, // 弹出框显示
      operate: 'query', // 当前操作
      selectInfo: {}, // 选中的数据
      confirmLoading: false, // Loading
      loading: false, // 导出loading
      deptInfo: [], // 部门信息
      treeOfOrg: [],
      orgid: '',
      orgname: '',
      url: '/admin/staff'// ajax请求地址
    }
  },
  created () {
    // 获取部门信息
    this.getDept().then((res) => {
      this.deptInfo = res.data
    })
    // 获取树形组织信息
    getOrgTree({ 'parentTreeId': 'root' }).then(res => {
      this.treeOfOrg = this.genernateTree(res.result.data)
    })
  },
  methods: {
    orgChange (value, name) {
      this.orgid = value
      this.orgname = name
    },
    /**
     * 处理后台返回值 替换名字 id=>key label=>title
     * 处理与树型绑定值冲突问题
     */
    genernateTree (value) {
      value.forEach(item => {
        item.value = item.id + 'select'
        item.title = item.label
        item.key = item.id
        if (item.children && item.children.length) {
          this.genernateTree(item.children)
        }
      })
      return value
    },
    getDept () {
      return query('/admin/codelist/byName?name=dept', 'GET', {}, {})
        .then(res => {
          return res.result
        })
    },
    /**
     * 搜索
     */
    search () {
      this.queryParam.deptCode = this.orgid === undefined ? '' : this.orgid.replace('select', '')
      this.$refs.stable.loadData({}, this.queryParam, {})
    },
    // 操作按钮
    modelMethod (action, selectInfo) {
      this.operate = action // 记录当前操作
      this.selectInfo = Object.assign({}, selectInfo) // 记录当前操作的数据
      const _this = this
      if (this.operate === 'del') { // 删除
        this.$confirm({
          title: '警告',
          content: `确认要删除该条记录吗?`,
          okText: '确认',
          okType: 'danger',
          cancelText: '取消',
          onOk () {
            _this.actionParam = {// 请求参数
              'url': _this.url + '/' + _this.selectInfo.id,
              'action': 'delete',
              'parameter': {},
              'data': {},
              'message': '删除成功'
            }
            // 调用请求
            method(_this.actionParam).then(res => {
              _this.$refs.stable.refresh(true)// 刷新列表
            })
          },
          onCancel: () => {
            this.$notification['info']({
              message: '取消删除操作',
              duration: 4
            })
          }
        })
      } else {
        this.modelVisible = true // 弹出框显示
      }
    },
    // 确认
    handleOk () {
      this.confirmLoading = true
      if (this.operate === 'detile') { // 详情
        this.confirmLoading = false
        // 关闭编辑框
        this.modelVisible = false
      }
      if (this.operate === 'add') { // 新增
        this.actionParam = {
          'url': this.url,
          'action': 'POST',
          'parameter': {},
          'data': this.selectInfo,
          'message': '新增成功'
        }
      }
      if (this.operate === 'edit') { // 修改
        this.actionParam = {
          'url': this.url,
          'action': 'PUT',
          'parameter': {},
          'data': this.selectInfo,
          'message': '修改成功'
        }
      }
      // 调用请求
      return method(this.actionParam).then(res => {
        this.confirmLoading = false
        // 关闭编辑框
        this.modelVisible = false
        // 刷新列表
        this.$refs.stable.refresh(true)
      })
    },
    exportExcel () {
      this.actionParam = {
        'url': this.url + '/export',
        'action': 'get',
        'parameter': this.queryParam,
        'data': {}
      }
      return download(this.actionParam).then(res => {
        this.download(res)
        this.loading = false
      })
    },
    /**
     * 下载
     */
    download (data) {
      if (!data) {
        return
      }
      const url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
      const link = document.createElement('a')
      link.style.display = 'none'
      link.href = url
      // 获取文件名
      // download 属性定义了下载链接的地址而不是跳转路径
      link.setAttribute('download', '人员基本信息.xlsx')
      document.body.appendChild(link)
      link.click()
      document.body.removeChild(link)
    }

  }
}
</script>
<style scoped>
.text-overflow {
    display:block;                     /*内联对象需加*/
    word-break:keep-all;           /* 不换行 */
    white-space:nowrap;          /* 不换行 */
}
</style>
